//
//  HomeProgramaCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/11/22.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "HomeProgramaCell.h"
#import "HomeProgramaLayout.h"
#import "HomeCollectionCell.h"
#import "GroupChatVC.h"
#import "YellowPageVC.h"
#import "KeepCallsController.h"
#import "ExchangeRateController.h"
#import <LEEAlert/LEEAlert.h>
#import "SelectedListView.h"
#import "RentHouseHomeVC.h"
#import "WineCategoryVC.h"
#import "MerchantListVC.h"
#import "EmploymentVC.h"
#import "LifeServiceController.h"
#import "PayMoneyController.h"
@interface HomeProgramaCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myCollectionH;

@property (nonatomic, strong) NSArray *dataModels;
@end

@implementation HomeProgramaCell
//车位房屋出租信息，在线报修，社区通知，建义表扬，
- (NSArray *)dataModels{
    
    if (_dataModels == nil) {
        
        _dataModels = @[@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"手机充值"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"缴纳电费"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"缴纳网费"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"菲度锦囊"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"房屋出租"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"求职招聘"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"汇率查询"},@{@"image" : @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511331357944&di=b39df823edd6e2f8b1cf98a08e39bc05&imgtype=0&src=http%3A%2F%2Fpic1.16pic.com%2F00%2F15%2F60%2F16pic_1560933_b.jpg",@"title" : @"企业黄页"}];
        
    }
    
    
    return _dataModels;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCollectionCell class]) bundle:nil] forCellWithReuseIdentifier:[HomeCollectionCell identifierStr]];
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.bottomMargin.constant = 6;
    
    self.myCollectionH.constant = 160;
}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 8;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

        HomeCollectionCell *cell = (HomeCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:[HomeCollectionCell identifierStr] forIndexPath:indexPath];
    
       cell.idex = indexPath;
        
        cell.model = self.dataModels[indexPath.row];
        
        return cell;
    
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    

    
    if (indexPath.item == 0) {
        
        if (!(myViewModel.userIsLogin)) {
            
            [myViewModel.rootController login];
            return;
        }

        KeepCallsController *temp = [[KeepCallsController alloc]init];


        [self.viewController.navigationController pushViewController:temp animated:YES];

    }else if (indexPath.item == 1) {
        
        if (!(myViewModel.userIsLogin)) {
            
            [myViewModel.rootController login];
            
            return;
        }
        
        PayMoneyController *temp = [[PayMoneyController alloc]init];
        
        temp.type = @"电费";
        
        temp.urlStr = self.model.electricity_bill;
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    }else if (indexPath.item == 2) {
        
        if (!(myViewModel.userIsLogin)) {
            
            [myViewModel.rootController login];
            return;
        }
        
        PayMoneyController *temp = [[PayMoneyController alloc]init];
        
        temp.type = @"网费";
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    }else if (indexPath.item == 3) {
        
        LifeServiceController *temp = [[LifeServiceController alloc]init];
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    }else if (indexPath.item == 4) {
        
        RentHouseHomeVC *temp = [[RentHouseHomeVC alloc]init];
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    } else if (indexPath.item == 5) {
        
        EmploymentVC *temp = [[EmploymentVC alloc]init];
        
        [self.viewController.navigationController pushViewController:temp animated:YES];
        
    }else if (indexPath.item == 6) {

        ExchangeRateController *temp = [[ExchangeRateController alloc]init];


        [self.viewController.navigationController pushViewController:temp animated:YES];
        

    }else if (indexPath.item == 7) {
        
        
        
        YellowPageVC *temp = [[YellowPageVC alloc]init];
        
        
        [self.viewController.navigationController pushViewController:temp animated:YES];

//        [self getWater];

    }
   
    
}


- (void)getWater{
    
    SelectedListView *view = [[SelectedListView alloc] initWithFrame:CGRectMake(0, 0, 280, 0) style:UITableViewStylePlain];
    
    view.isSingle = YES;
    
    
    view.array = @[[[SelectedListModel alloc] initWithSid:0 Title:@"呼叫送水工"] ,
                   [[SelectedListModel alloc] initWithSid:1 Title:@"线上购买"]
                   ];
    
    
    MJWeakSelf;
    view.selectedBlock = ^(NSArray<SelectedListModel *> *array) {
        
        [LEEAlert closeWithCompletionBlock:^{
            
            if ([[array firstObject].title isEqualToString:@"呼叫送水工"]) {
                
                  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://13720343150"]];
                
            } else {
               
                WineCategoryVC *temp = [[WineCategoryVC alloc]init];
                
                temp.type = @"wine";
                
                temp.seletIndex = 0;
                
                [weakSelf.viewController.navigationController pushViewController:temp animated:YES];
                
            }
            
   
            
            
        }];
        
    };
    
    [LEEAlert alert].config
    .LeeTitle(@"选择定水方式")
    .LeeItemInsets(UIEdgeInsetsMake(10, 0, 0, 0))
    .LeeCustomView(view)
    .LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
    .LeeHeaderInsets(UIEdgeInsetsMake(10, 0, 0, 0))
    .LeeClickBackgroundClose(YES)
    .LeeShow();
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
